package cs342.project1.mathNotebook.gui;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

class RadioButtonPanel extends JPanel {
    JRadioButton[] buttons;

    RadioButtonPanel(String[] str) {
      setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
      buttons = new JRadioButton[str.length];
      for (int i = 0; i < buttons.length; i++) {
        buttons[i] = new JRadioButton(str[i]);
        buttons[i].setFocusPainted(true);
        buttons[0].setSelected(true);
        
        add(buttons[i]);
      }
    }
    
    public void setSelectedIndex(int index) {
      for (int i = 0; i < buttons.length; i++) {
        buttons[i].setSelected(i == index);
      }
    }

    public int getSelectedIndex() {
      for (int i = 0; i < buttons.length; i++) {
        if (buttons[i].isSelected()) {
          return i;
        }
      }
      return -1;
    }

    public JRadioButton[] getButtons() {
      
      return buttons;
    }
  }
